package com.asianrapid.demo.core;

import com.asianrapid.core.exception.AsianServiceException;

/**
 * 自定义的业务异常类
 */
public class BusinessException extends AsianServiceException {

    public BusinessException(ExceptionConstant iwe) {
        setCode(iwe.getCode());
        setDetailMessage(iwe.getMessage());
    }

    public BusinessException(ExceptionConstant iwe, String[] args) {
        setCode(iwe.getCode());

        String msg = iwe.getMessage();
        for(int a = 0 ; a < args.length ; a++){;
            msg = msg.replace("%"+(a+1)+"%",args[a]);
        }

        setDetailMessage(msg);


    }

    public BusinessException(ExceptionConstant iwe, Exception e) {
        this.setStackTrace(e.getStackTrace());
        setCode(iwe.getCode());
        setDetailMessage(iwe.getMessage());
    }

    public BusinessException(ExceptionConstant iwe, Exception e, String[] args) {
        this.setStackTrace(e.getStackTrace());
        setCode(iwe.getCode());
        String msg = iwe.getMessage();
        for(int a = 0 ; a < args.length ; a++){;
            msg = msg.replace("%"+(a+1)+"%",args[a]);
        }

        setDetailMessage(msg);
    }

    public BusinessException(ExceptionConstant iwe, String detailMessage) {
        super(detailMessage);
        setCode(iwe.getCode());
        setDetailMessage(detailMessage);
    }

    public BusinessException(ExceptionConstant iwe, Object detailData) {
        super(iwe.getMessage());
        setCode(iwe.getCode());
        setDetailData(detailData);
    }
}
